package myPackage.participant.dao;

import myPackage.participant.domain.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

@Repository
public class StudentDao {
    @Autowired
    private HibernateTemplate hibernateTemplate;

    public List<Student> listAllStudents() {
        return hibernateTemplate.loadAll(Student.class);
    }
       //by id
    public Student getStudentByUsername(String username){
        List resultList =  hibernateTemplate.find("from Student where username=?",username);
        return  resultList.size() == 0?null:(Student)resultList.get(0);
    }

    public void insert(Student newStudent)
    {
        hibernateTemplate.save(newStudent);
    }

    public void update(Student informationUploaded) {
        hibernateTemplate.update(informationUploaded);
    }
}
